public static void bubbleSort(int data[], int n)
// pre: 0 <= n <= data.length
// post: values in data[0..n-1] in ascending order
{
	int numSorted = 0; // number of values in order
	int index; // general index
	while (numSorted < n)
	{
		// bubble a large element to higher array index
		for (index = 1; index < n-numSorted; index++)
		{
			if (data[index-1] > data[index])
				swap(data,index-1,index);
		}
		// at least one more value in place
		numSorted++;
	}
}